(function() {
	var skill = {
		//非安全，添加BUFF
		_addBuff: function(buff_id) {
			var buffs = this.buffs || (this.buffs = []);
			if (buffs.indexOf(buff_id) === -1) {
				buffs.push(buff_id);
				this.buffs = buffs.filter(function(buff_id) {
					return BuffCon.get(buff_id)
				});
				this.save();
			}
		},
		//代码片段，删除BUFF
		_removeBuff: function(buff_id) {
			var buffs = this.buffs || [];
			this.buffs = $Array.remove(buffs, buff_id);
			this.save();
		},
		//获取拥有的可用BUFF（包括真正使用与未使用），如果BUFF过期或者不存在，自动移除
		getBuffs: function() {
			var buffs = (this.buffs || []).slice();
			var _new_buffs = [];
			var result = [];
			buffs.forEach(function(buff_id) {
				var buff = BuffCon.get(buff_id);
				if (buff && buff.isUseAble()) {
					_new_buffs.push(buff_id);
					result.push(buff);
				}
			});
			//BUFF列表中有过期的或者已经失效的，更新BUFF列表
			if (_new_buffs.length !== buffs.length) {
				this.buffs = _new_buffs;
				this.save();
			}
			//混合商家的BUFF
			var bus = BusCon.get(this.bus_id);
			bus && result.concat(bus.getBuffs());
			return result;
		},
		getBuffsDetail: function() {
			return this.getBuffs();
		},
		emitBuffs: function(buffEnv, callBy, other_args) {
			var buffs = this.getBuffs();
			var self = this;
			buffs.forEach(function(buff) {
				buff.emit({
					env: buffEnv,
					callBy: callBy,
					goods_id: self._id,
					goods: self,//带着已经init-cash的goods引用对象进去对进行cash重计算
					other_args: other_args
				});
			});
		},
		/*
		 *拓展方法
		 */
		//获取
		getEndPayCallbackBuff: function() {
			var goods = this;
			var goods_buffs = goods.getBuffs();
			var cb_url_buff;
			goods_buffs.every(function(buff) {
				if (buff.code_id === "商品交易完成访问回调地址") {
					cb_url_buff = buff
				} else {
					return true;
				}
			});
			return cb_url_buff;
		}
	}
	module.exports = skill;

	var db = require("../db/index");
	var config = require("../_include/config");
	var UserAddressCon = require("../user_address/_con");
	var AchCon = require("../ach/_con");
	var data_cut = require("../_include/data_cut");
	var CommentCon = require("../comment/_con");
	var EvaluationCon = require("../eval/_con");
	var ClassifyCon = require("../bus.classify/_con");
	var TagCon = require("../bus.tag/_con");
	var BusCon = require("../bus/_con");
	var BuffCon = require("../buff/_con");
	var buffCode = require("../buff/buff_code");
	var $Object = require("../_include/$.Object");
	var $Array = require("../_include/$.Array");
	var helper = require("../_include/helper");
	var xss = require("xss");


}());